package com.thiswhyme.demo.msgpush.core.event;

import com.thiswhyme.demo.msgpush.core.event.bean.EventType;
import com.thiswhyme.demo.msgpush.core.event.bean.WebSocketEvent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;

/**
 * @description: WebSocket消息广播事件处理器
 * @author: thiswhyme
 * @date: 2021/9/28
 */
@Slf4j
public abstract class AbstractBroadcastEventHandler implements EventHandler {

    @Override
    public EventType supportType() {
        return EventType.BROADCAST;
    }

    @Override
    public void handle(WebSocketEvent event) {
        String msgContent = event.getMsgContent();
        log.debug("【ws消息广播事件】处理，内容：{}", msgContent);
        if (!StringUtils.hasText(msgContent)) {
            log.error("消息广播失败，消息内容为空");
            return;
        }

        doHandle(event);
    }

    /**
     * ws消息广播事件处理
     * @param event
     */
    public abstract void doHandle(WebSocketEvent event);
}
